//
//  MyInfoViewController.m
//  Wechat
//
//  Created by FONERY on 2019/9/9.
//  Copyright © 2019 Zhangfan. All rights reserved.
//

#import "MyInfoViewController.h"
#import "MyInfoTableViewCell.h"
#import "MyInfoModel.h"

@interface MyInfoViewController () <UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSArray *myInfoArr;
@end

@implementation MyInfoViewController

- (NSArray *)myInfoArr {
    if (!_myInfoArr) {
        MyInfoModel *head = [[MyInfoModel alloc] init];
        head.title = @"头像";
        head.image = @"App_emp_headimg";
        head.type = MyInfoTableViewCellTypeHead;
        
        MyInfoModel *nickName = [[MyInfoModel alloc] init];
        nickName.title = @"昵称";
        nickName.detail = @"131****0073";
        nickName.type = MyInfoTableViewCellTypeDetail;
        
        MyInfoModel *account = [[MyInfoModel alloc] init];
        account.title = @"账号";
        account.detail = @"1698706";
        account.type = MyInfoTableViewCellTypeDetail;
//        account.type = MyInfoTableViewCellTypeNormal;
        
        MyInfoModel *more = [[MyInfoModel alloc] init];
        more.title = @"更多";
        more.type = MyInfoTableViewCellTypeAccessory;
        
        _myInfoArr = @[@[head, nickName, account], @[more]];
    }
    return _myInfoArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"个人信息";
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return [self.myInfoArr count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.myInfoArr[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyInfoTableViewCell *cell = [MyInfoTableViewCell cellWithTableView:tableView];
    cell.myInfoModel = self.myInfoArr[indexPath.section][indexPath.row];
    return cell;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0 && indexPath.row == 0) {
        return [MyInfoTableViewCell cellHeight];
    }
    return [MyInfoTableViewCell cell2Height];
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc] init];
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] init];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}

@end
